package com.easyui_server.model;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.solution.framework.model.BaseBean;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * Created with generator tools.
 * User: sunguangzhu
 * DateTime:2014-02-19 05:00:53
 */
@Entity
@Table(name = "t_group")
public class Group extends BaseBean implements java.io.Serializable {

    /**
     * 名称
     */
    private String name;

    /**
     * parent
     */
    private Group parent;

    /**
     * 用户集合
     */
    private java.util.Set<com.easyui_server.model.User> users;

    /**
     * default constructor
     */
    public Group() {
    }

    /**
     * full constructor
     *
     * @param name
     * @param users
     */
    public Group(String name, java.util.Set<com.easyui_server.model.User> users) {
        this.name = name;
        this.users = users;
    }

    /**
     * getter
     */
    @Column
    public String getName() {
        return this.name;
    }

    /**
     * setter
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * getter
     */
    @JsonBackReference
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "group")
    public java.util.Set<com.easyui_server.model.User> getUsers() {
        return this.users;
    }

    /**
     * setter
     *
     * @param users
     */
    public void setUsers(java.util.Set<com.easyui_server.model.User> users) {
        this.users = users;
    }

    @JsonManagedReference
    @ManyToOne(fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "parent_id")
    public Group getParent() {
        return parent;
    }

    public void setParent(Group parent) {
        this.parent = parent;
    }
}
